"""
chord.models

contains the django database object, and our custom Server guy that gets passed around.
"""

from django.db import models

class Finger(models.Model):
    def __init__(self, *args, **kwargs):
        if 'server' not in kwargs:
            ip = ""
            port = -1
            key = ""
            status = 'U'
        else: # it is in kwargs
            server = kwargs['server']
            ip = server.ip
            port = server.port
            key = server.key
            status = server.status
        super(Finger,self).__init__(ip = ip, port = port, key = key, status = status,*args,**kwargs)

    FINGER_STATUS_CHOICES = (
        ('U', 'Unknown'),
        ('A', 'Active'),
        ('L', 'Leaving'),
    )
    i = models.IntegerField(primary_key=True)
    ip = models.IPAddressField()
    port = models.IntegerField()
    key = models.CharField(max_length=40)
    status = models.CharField(max_length=1, choices=FINGER_STATUS_CHOICES)
    
    def __unicode__(self):
         return u'<Finger: ip:%s, port:%d, status:%s>' % (self.ip, self.port, self.status)


